package com.summit.exam.servlet;

import com.summit.exam.dbdao.GradeDao;
import com.summit.exam.dbdao.PaperDao;
import com.summit.exam.entity.PaperBean;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

public class UpdateTestServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");

        String score = req.getParameter("score");

        GradeDao gradeService = new GradeDao();
        boolean ok = gradeService.updateGrade(Integer.parseInt(score));
        PrintWriter pw = resp.getWriter();

        if (ok){
            PaperDao paperService = new PaperDao();
            ArrayList<PaperBean> paperArrayList = paperService.selectPerpar();
            req.setAttribute("paperArrayList", paperArrayList);

        }else {

            pw.println("<script language='javascript'>alert('修改失败')</script>");
            pw.println("<script>window.history.go(-1)</script>");
        }

        req.getRequestDispatcher( "/ExamSystem/techweb/ModifyTest.jsp").forward(req, resp);
    }
}
